
// Routines related to .ini variables and variables.h

#define EXTERN
#include "variables.h"
#include "system.h"
#include <stdlib.h>
#include "main.h"

uint32_t i;

void init_variables(void)
{
    Set_Page_Locations();

#define TESTING
#ifdef TESTING
    // move the first flash page into ram so we can put reasonable values in place
    Page_Ptr[0] = calloc(2048,1);
    N_Cyl = 6;
    N_Teeth = 58;
    Missing_Teeth=2;
    //Max_Inj_Time = 10000;       // usec
    //Load_Dot = RPM = 1234;      // for testing if there is no tuner
    //V_MAP[0] = 13;              // testing
    Load = 3276; //20% bin 14
    V_Batt = 2290;
    IAT = 9830; //0.6 bin 14
    for (i = 0; i < N_Cyl; ++i) {
      Cyl_Offset_Array[i] = (i * 3000);
    };
    Engine_Position = 8750;//350 degrees
    Drop_Dead_Angle = 13500; //540
    Ignition_Type = 0;

#endif

}

// set pointers to where every page is in flash

void Set_Page_Locations(void)
{
    uint_fast16_t i;
    uint8_t *ptr = Flash_Addr[Flash_Block] + 1024;      // leave room for other data

    // page positions in flash
    for (i = 0; i < nPages; ++i) {
        Page_Ptr[i] = ptr;
        ptr += Max_Page_Size;   // used fixed spacing
    }                           // for
}
